package com.codeforces.contest.c313;
import java.util.Scanner;


public class _313B {

	static Scanner scanner = new Scanner(System.in);
	static String s;
	static int[] count;
	static int m, fr, to;

	public static void main(String[] args) {
		s = scanner.next();		
		count = new int[s.length()];
		if (s.charAt(0) == s.charAt(1)) {
			count[0] = 1;
		}
		else {
			count[0] = 0;
		}
		for (int i=1;i<s.length()-1;++i) {
			if (s.charAt(i) == s.charAt(i+1)) {
				count[i] = 1 + count[i-1];
			}
			else {
				count[i] = count[i-1];
			}
		}
		if (s.length() >= 2) {
			count[s.length()-1] = count[s.length()-2];
		}
//		
//		for (int i=0;i<s.length();++i) {
//			System.out.print(count[i] + " ");
//		}
//		System.out.println();
		
		m = scanner.nextInt();
		for (int i=1;i<=m;++i) {
			fr = scanner.nextInt() - 1;
			to = scanner.nextInt() - 1;
			if (fr == 0) {
				System.out.println(count[to-1]);
			}
			else {
				System.out.println(count[to-1] - count[fr-1]);
			}
		}

	}

}
